import 'package:cbec_app/components/base/base_image.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:video_player/video_player.dart';

class VideoControls extends StatelessWidget {
  ///视频配置
  final Map<String, dynamic> info;

  final VideoPlayerController controller;
  const VideoControls(
      {super.key, required this.controller, required this.info});

  @override
  Widget build(BuildContext context) {
    return Stack(
      children: <Widget>[
        AnimatedSwitcher(
          duration: const Duration(milliseconds: 50),
          reverseDuration: const Duration(milliseconds: 200),
          child: controller.value.isPlaying
              ? const SizedBox.shrink()
              : ColoredBox(
                  color: Colors.black26.withOpacity(0.5),
                  child: const Center(
                    child: Icon(
                      Icons.play_circle,
                      color: Colors.white,
                      size: 64,
                      semanticLabel: 'Play',
                    ),
                  ),
                ),
        ),
        GestureDetector(
          onTap: () {
            controller.value.isPlaying ? controller.pause() : controller.play();
          },
        ),
        controller.value.isInitialized
            ? const SizedBox.shrink()
            : (info['surfacePlotImage'] != ''
                ? BaseImage(url: info['surfacePlotImage'], width: getUseWidth())
                : const SizedBox.shrink()),
      ],
    );
  }

  ///获取页面边距
  double getMargin() {
    return (info['pagePadding'] as int).toDouble();
  }

  ///获取可用宽度
  double getUseWidth() {
    return 375.w - getMargin() * 2;
  }
}
